﻿using System.Collections.Generic;
using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.UxDesigns.Controls.Renderers;


namespace T4UtilityBelt.UxDesigns.Controls
{
    public class GridControl : PanelControl<GridControl, IGridRenderer>
    {
        public GridControl()
        {
            _columns = new GridColumnCollection();
            _rows = new GridRowCollection();
        }

        private readonly GridColumnCollection _columns;

        public GridColumnCollection Columns
        {
            get { return _columns; }
        }

        private readonly GridRowCollection _rows;

        public GridRowCollection Rows
        {
            get { return _rows; }
        }

        #region methods

        public override IEnumerable<Control> AllControls()
        {
            if (HasControls)
            {
                foreach (var c in Controls)
                {
                    yield return c;
                    foreach (Control cc in c.AllControls())
                    {
                        yield return cc;
                    }
                }
            }
            foreach (var cx in Columns)
            {
                //yield return cx;
                foreach (Control cc in cx.AllControls())
                {
                    yield return cc;
                }
            }
            foreach (var cy in Rows)
            {
                //yield return cy;
                foreach (Control cc in cy.AllControls())
                {
                    yield return cc;
                }
            }
        }

        public override void FixModel(Entity entity)
        {
            base.FixModel(entity);
            foreach (IContentElement c in Columns)
            {
                c.FixModel(entity);
            }
            foreach (IContentElement c in Rows)
            {
                c.FixModel(entity);
            }
        }

        #endregion methods
    }
}